#include "kstd.h"
#include "write.h"
#include "multiboot.h"


void printf(const char* format, ...);
static inline
void outb( unsigned short port, unsigned char val )
{
  asm volatile( "outb %0, %1"
		: : "a"(val), "Nd"(port) );
}

static inline
unsigned char inb( unsigned short port )
{
  unsigned char ret;
  asm volatile( "inb %1, %0"
		: "=a"(ret) : "Nd"(port) );
  return ret;
}

unsigned char kbdus[128] =
  {
    0,  27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
    '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
    0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
    '\\', 'z', 'x', 'c', 'v', 'b', 'n',
    'm', ',', '.', '/',   0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, '-', 0, 0, 0, '+', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  };

void keyboard()
{
  printf("Bouh  !\n");
}

int getkey ()
{
  int r = 0;

  while (1)
    {
      if (inb(0x64) & 1)
	{
	  r = inb(0x60);
	  if (r & 128)
	    {
	      // printf("KEY RELEASE\n");
	    }
	  else
	    {
	      return (kbdus[r]);
	    }
	}
    }
}

void init_pics()
{

}
